//
//  File.swift
//
//
//  Created by didi on 2022/9/8.
//

import Vapor

struct SystemInstallGuardMiddleware: AsyncMiddleware {
    func respond(to request: Request, chainingTo next: AsyncResponder) async throws -> Response {
        let allowUrl = "/" + request.molecular.config.paths.install + "/" + request.molecular.config.install.currentStep + "/"
        if !request.molecular.installIsComplated && request.url.path != allowUrl {
            return request.redirect(to: allowUrl)
        } else {
            return try await next.respond(to: request)
        }
    }
}
